<template>
	<view class="container">
		<view class="paging">
			<view class="paging-item" v-for="(item,index) in dataList" :key="index">
				<view class="date">
					<text>{{checkDateIsTodayOrYesterday(item.recordTime)}}</text>
					<u-icon size="24" name="https://jht-public.oss-cn-shenzhen.aliyuncs.com/2024/8/a4bd16d7-3800-4a56-a868-cf7623c59e70.png"></u-icon>
				</view>
				<view class="video-wrap">
					<view class="list">
						<view class="item" v-for="(v,i) in item.videoHistoryList" :key="i" @click="to_video(v.videoInfoId)">
							<view class="cover">
								<u-image :src="v.videoImg" :lazy-load="true" radius="12" v-if="v.videoImg"></u-image>
								<u-image src="https://jht-public.oss-cn-shenzhen.aliyuncs.com/2024/8/a8dedf10-b511-4c59-8ac2-058b823b01bf.png" :lazy-load="true" radius="12" v-else></u-image>
								<view class="time">{{v.videoTime}} / {{v.duration}}</view>
							</view>
							<view class="item-r">
								<view class="title">{{v.headline}}</view>
								<view class="chapter">
									{{ v.chapter }} ·  {{checkDateIsTodayOrYesterday(v.recordTime)}} {{changeUpdateTime(v.updateTime)}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import dayjs from 'dayjs'
	//引入请求文件
	import {listing} from '../../api/api.js'
	import {history} from '../../api/request.js'
	export default {
		data(){
			return{
				dataList:[]
			}
		},
		created() {
			this.getHistory()
		},
		methods:{
			checkDateIsTodayOrYesterday(value){
				const date = dayjs(value);
				const today = dayjs().startOf('day');
				const yesterday = today.subtract(1, 'day');
				if (date.isSame(today, 'day')) {
					return '今天';
				}else if(date.isSame(yesterday, 'day')){
					return '昨天';
				}else{
					return date.format('YYYY-MM-DD');
				}
			},
			changeUpdateTime(dateStr){
				return dayjs(dateStr).format('HH:mm');
			},
			getHistory(){
				listing(history)
				.then(res=>{
					if(res.data.code == 200){
						const { data } = res.data
						this.dataList = data
					}
				})
			},
			//跳转到视频
			to_video(videoInfoId){
				uni.navigateTo({
					url:'../../packagesVideo/video/video?id='+videoInfoId
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		width: 100%;
		height: 100vh;
		background: #F6F7F8;
		padding: 32rpx 24rpx;
		box-sizing: border-box;
		.paging{
			&-item{
				margin-bottom: 30rpx;
				.date{
					display: flex;
					align-items: center;
					color: #140F08B3;
					margin-bottom: 30rpx;
				}
				.video-wrap{
					.list{
						.item{
							display: flex;
							background: #fff;
							border-radius: 16rpx;
							padding: 24rpx;
							margin-bottom: 24rpx;
							box-sizing: border-box;
							.cover{
								position: relative;
								/deep/.u-image{
									width: 248rpx !important;
									height: 140rpx !important;
								}
								/deep/.u-image__image{
									width: 248rpx !important;
									height: 140rpx !important;
								}
								/deep/.u-image__error{
									width: 248rpx !important;
									height: 140rpx !important;
								}
								.time{
									position: absolute;
									bottom: 12rpx;
									right: 12rpx;
									font-size: 24rpx;
									color: #fff;
									font-weight: 500;
								}
							}
							&:last-child{
								margin-bottom: 0;
							}
							.item-r{
								display: flex;
								flex-direction: column;
								justify-content: space-between;
								margin-left: 24rpx;
								.title{
									font-size: 28rpx;
									font-weight: bold;
									color: #333;
									display: -webkit-box;
									-webkit-line-clamp: 2;
									-webkit-box-orient: vertical;
									overflow: hidden;
									padding-top: 6rpx;
								}
								.chapter{
									color: #898783;
									font-size: 20rpx;
									padding-bottom: 6rpx;
								}
							}
						}
					}
				}
			}
		}
	}
</style>